package com.cet.designpatterns.singleton.type7;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-08-30 23:15
 **/
public class Singleton {

    private Singleton() {

    }

    //静态内部类，该类中有一个静态属性Singleton
    private static class SingletonInstance{
        private static final Singleton INSTANCE = new Singleton();
    }

    public static Singleton getInstance() {
        return SingletonInstance.INSTANCE;
    }
}

/*
* Singleton类装载的时候，静态内部类SingletonInstance并不会装载
* 调用静态方法getInstance时，SingletonInstance进行类装载（JVM类装载线程安全），类的静态属性只会在第一次加载类的时候初始化
* */
